import { defineStore } from 'pinia'

import { loginIn } from '@/api/login'
import type { LoginParams } from '@/api/types/login.type'
export const useLoginStore = defineStore('login', {
  state: () => ({
    token: ''
  }),

  actions: {
    async LOGIN_IN(dataP: LoginParams) {
      const {
        data: {
          data,
          meta: { status }
        }
      } = await loginIn(dataP)
      if (status !== 200) return false

      const token = data?.token
      this.token = token as string
      return true
    }
  },
  persist: true
})
